package pkg

import (
	"fmt"
	"golang.org/x/crypto/bcrypt"
)

// 生成带盐密码

func GenSaltPassword(password string) (string, error) {
	SaltedPwd, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		return "", err
	}
	return string(SaltedPwd), nil
}

// 验证密码

func VerifyPassword(password string, salted string) error {
	err := bcrypt.CompareHashAndPassword([]byte(salted), []byte(password))
	fmt.Println(bcrypt.Cost([]byte(salted)))
	if err != nil {
		return err
	}
	return nil
}
